package com.ellricky.baselib.util;

import android.app.Activity;

import com.andr.common.util.EmptyUtil;
import com.andr.common.util.ToastUtil;

import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;

public abstract class NewJOCallback extends NewEBaseCallback {

    public NewJOCallback(@Nullable Activity context) {
        super(context);
    }

    public NewJOCallback(@Nullable Activity context, boolean showLoading) {
        super(context, showLoading);
    }

    public NewJOCallback(@Nullable Activity context, boolean showLoading, @Nullable String loadMsg) {
        super(context, showLoading, loadMsg);
    }

    @Override
    public int dataFlag() {
        return 1;
    }

    @Override
    public void parseDataJO(String code, String msg, JSONObject dataJO) {
        super.parseDataJO(code, msg, dataJO);
        if ("1".equals(code)) {
            this.onSuccess(dataJO, msg);
        } else {
            this.onErrorCode(dataJO, code, msg);
        }

    }

    protected abstract void onSuccess(JSONObject var1, String var2);

    protected void onErrorCode(JSONObject dataJO, String code, String msg) {
        if (!EmptyUtil.isEmpty(msg)) {
            ToastUtil.show(this.getMContext(), msg);
        }

    }
}
